package org.jeecg.modules.monitoring.j_monitoring.service.impl;

import org.jeecg.common.util.RedisUtil;
import org.jeecg.modules.monitoring.j_monitoring.constantConfig.RoomRedisEnum;
import org.jeecg.modules.monitoring.j_monitoring.entity.GatewayWarningCount;
import org.jeecg.modules.monitoring.j_monitoring.entity.RingWarning;
import org.jeecg.modules.monitoring.j_monitoring.mapper.RingWarningMapper;
import org.jeecg.modules.monitoring.j_monitoring.service.IRingWarningService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.ArrayList;

/**
 * @Description: ring_warning
 * @Author: xiaoyq
 * @Date:   2023-09-24
 * @Version: V1.0
 */
@Service
public class RingWarningServiceImpl extends ServiceImpl<RingWarningMapper, RingWarning> implements IRingWarningService {

    @Autowired
    private RedisUtil redisUtil;

    @Override
    public void removeAll() {
        baseMapper.removeAll();
    }

    public GatewayWarningCount queryOneCount(String fdn){
        return baseMapper.queryOneCount(fdn);
    }

    public Object queryWarningByName(String name){
        String key = "";

        switch (name){
            case "数据机房":
                key = RoomRedisEnum.dataRoom.getKey();
                break;
            case "网络机房":
                key = RoomRedisEnum.netRoom.getKey();
                break;
            case "UPS间":
                key = RoomRedisEnum.upsRoom.getKey();
                break;
            default:
                return new ArrayList<>();
        }

        if (redisUtil.hasKey(key) && redisUtil.get(key) != null){
            return redisUtil.get(key);
        }

        return baseMapper.selectByEventSource(name);
    }
}
